<template>
	<view class="goods-manage-item">
		<view class="goods-title">
			<view class="time"> 创建时间：{{goodsInfo.create_time}} </view>
			<view class="status" :class="goodsInfo.active==1?'a-status':''"> {{goodsInfo.active==1?'上架':'下架'}} </view>
			<!-- <view class="a-status"> 上架 </view> -->
		</view>
		<view class="goods-info">
			<image :src="goodsInfo.img" class="img" />
			<view class="goods-details">
				<view class="goods-name"> {{goodsInfo.name}} </view>
				<view class="goods-num">
					<view class="goods-price"> ￥<text>{{goodsInfo.price}}</text> </view>
					<view class="goods-kc"> 库存：{{goodsInfo.stock}} </view>
				</view>
				<view class="sales">
					<!-- <view class="sales-item">
						<view class="label"> 显示销量 </view>
						<view class="value"> {{goodsInfo.show_num}} </view>
					</view> -->
					<view class="sales-item">
						<view class="label"> 实际销量 </view>
						<view class="value"> {{goodsInfo.sales}} </view>
					</view>
					<view class="sales-item">
						<view class="label"> 今日销量 </view>
						<view class="value"> {{goodsInfo.sales_day}} </view>
					</view>
				</view>
			</view>
		</view>
		<view class="btn-box">
			<!-- <view class="btn"> 复制 </view> -->
			<view class="btn" @tap="modalRef.open()"> 删除 </view>
			<view class="btn" @tap="editGoods"> 编辑 </view>
			<view class="btn a-btn" @tap="editStatus(goodsInfo.spu, 0)" v-if="goodsInfo.active == 1"> 下架 </view>
			<view class="btn a-btn" @tap="editStatus(goodsInfo.spu, 1)" v-else> 上架 </view>
		</view>
		<Modal tips="确定删除该商品吗？" ref="modalRef" @confirm="delGoods"/>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import Modal from '@/components/Modal.vue'
	import { EditGoodsStatusApi, DelGoodsApi } from '@/service/shop.js'
	const props = defineProps(['goodsInfo'])
	const emit = defineEmits(['del'])
	const modalRef = ref()
	// 修改商品状态
	const editStatus = (spu, active) => {
		let params = { spu, active }
		EditGoodsStatusApi(params).then(res => {
			props.goodsInfo.active = active
		})
	}
	// 删除商品
	const delGoods = (spu) => {
		DelGoodsApi({spu: props.goodsInfo.spu}).then(res => {
			emit('del')
		})
	}
	// 编辑商品
	const editGoods = () => {
		uni.navigateTo({
			url: `/pages/shopPages/releaseGoods/editGoods?info=${JSON.stringify(props.goodsInfo)}`
		})
	}
</script>

<style scoped lang="scss">
	.goods-manage-item {
		margin-bottom: 10px;
		border-radius: 10px;
		background-color: #fff;
		padding: 15px 10px 14px;
		.goods-title {
			font-size: 14px;
			font-weight: 400;
			line-height: 16px;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 8px;
			border-bottom: 1px solid #eeeeee;
			.time {
				color: #999999;
			}
			.status {
				color: #999999;
			}
			.a-status {
				color: #FF3B1E;
			}
		}
		.goods-info {
			padding: 10px 0;
			display: flex;
			align-items: center;
			.img {
				width: 80px;
				height: 80px;
				margin-right: 10px;
				border-radius: 10px;
			}
			.goods-details {
				flex: 1;
				.goods-name {
					color: #333333;
					font-size: 16px;
					font-weight: 500;
					line-height: 24px;
				}
				.goods-num {
					display: flex;
					align-items: center;
					margin-bottom: 6px;
					.goods-price {
						color: #FF3B1E;
						font-size: 10px;
						font-weight: 600;
						line-height: 20px;
						margin-right: 10px;
						text {
							font-size: 15px;
						}
					}
					.goods-kc {
						color: #999999;
						font-size: 12px;
						font-weight: 400;
						line-height: 14px;
					}
				}
				.sales {
					display: flex;
					align-items: center;
					.sales-item {
						flex: 1;
						.label {
							color: #999999;
							font-size: 12px;
							font-weight: 400;
							line-height: 14px;
							margin-bottom: 4px;
						}
						.value {
							color: #333333;
							font-size: 12px;
							font-weight: 400;
							line-height: 14px;
						}
					}
				}
			}
		}
		.btn-box {
			display: flex;
			align-items: center;
			justify-content: end;
			.btn {
				width: 60px;
				height: 28px;
				color: #333333;
				font-size: 14px;
				font-weight: 400;
				margin-left: 10px;
				line-height: 28px;
				text-align: center;
				background: #FFFFFF;
				border-radius: 151px;
				border: 1px solid #999999;
				box-sizing: border-box;
				&.a-btn {
					border: none;
					color: #FFFFFF;
					background: #FF3B1E;
				}
			}
		}
	}
</style>